// This code is licensed under New BSD Licence. For details see project page at
// http://code.google.com/p/hrissan-cocoa-helpers/source/checkout

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "Common.h"

@interface CellLoader : NSObject {
	IBOutlet UITableViewCell	*cell;
	IBOutlet UIView	*view;
}

@property (nonatomic, retain) UITableViewCell * cell;
@property (nonatomic, retain) UIView * view;

+ (CellLoader*) createWithNib:(NSString *)name;
- (id)initWithNib:(NSString*)name;

@end

template<class T>
T * deque_or_load_cell(UITableView * tv, NSString * name)
{
	UITableViewCell * cell = [tv dequeueReusableCellWithIdentifier:name];
	if( cell == nil )
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
		cell = [CellLoader createWithNib:name].cell;
#else
    cell = [[[T alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:name] autorelease];
#endif
	return objective_c_cast<T>(cell);
}
